package com.jacobson.huobi.mvp.presenter

import com.jacobson.core.di.annotation.ActivityScope
import com.jacobson.core.mvp.BasePresenter
import com.jacobson.huobi.common.expansion.applySchedulersIoMain
import com.jacobson.huobi.common.expansion.onRespResult
import com.jacobson.huobi.common.expansion.onResponseResult
import com.jacobson.huobi.common.expansion.onResult
import com.jacobson.huobi.entities.LoginUserInfo
import com.jacobson.huobi.entities.RegisterInfo
import com.jacobson.huobi.entities.response.LoginPageResponse
import com.jacobson.huobi.mvp.contract.LoginContract
import java.lang.Exception
import javax.inject.Inject

@ActivityScope
class LoginPresenter @Inject constructor(
    view: LoginContract.View,
    model: LoginContract.Model
) : BasePresenter<LoginContract.View, LoginContract.Model>(view, model),
    LoginContract.Presenter {
    override fun getVertiCode(phone: String) {
        model.getVertiCode(phone)
            .applySchedulersIoMain()
            .onRespResult(view) { resp ->
                view?.onVertiCodeResultResp(resp)
            }

    }

    override fun registerUser(registerInfo: RegisterInfo) {
        model.registerUser(registerInfo)
            .applySchedulersIoMain()
            .onRespResult(view) { resp ->
                view?.onRegisterResultResp(resp)
            }

    }

    override fun getKaptcha() {

        model.getKaptcha()
            .applySchedulersIoMain()
            .onResponseResult(view) {resp ->
                view?.onGetKaptchaResultResp(resp)
            }
    }

    override fun login(loginUserInfo: LoginUserInfo) {
        model.login(loginUserInfo)
            .applySchedulersIoMain()
            .onResponseResult(view) { resp ->
                view?.onLoginResultResp(resp)
            }
    }


}
